package com.csn.Comtroller;

import com.csn.entities.ResultData;
import com.csn.entities.StudentScore;
import com.csn.entities.StudentScoreOV;
import com.csn.entities.User;
import com.csn.service.impl.StudentServiceImpl;
import com.csn.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@CrossOrigin
public class IndexController {

    @Autowired
    private UserServiceImpl userService;

    @Autowired
    private StudentServiceImpl studentService;

    @RequestMapping("query_user")
    @ResponseBody
    public List<User> queryUser(){

        return userService.queryUser();
    }

    @RequestMapping("query_student")
    @ResponseBody
    public List<StudentScoreOV> queryStudentScore(){
        List<StudentScore> studentScores=studentService.queryStudentScore();
        List<StudentScoreOV> studentScoreOVS=new ArrayList<StudentScoreOV>();
        for (StudentScore student:studentScores) {
            studentScoreOVS.add(new StudentScoreOV(student.getType(),student.getCount()));
        }
        return studentScoreOVS;
    }
    @RequestMapping("query_student2")
    @ResponseBody
    public ResultData queryStudentID(){
        List<StudentScore> studentScores=studentService.queryStudentScore();
        return new ResultData(0,"123",100,studentScores);

    }

    

}
